using QFramework;

namespace ProjectChildhood
{
	public partial class AudioController : ViewController, ISingleton
	{
		public static  AudioController Instance => MonoSingletonProperty<AudioController>.Instance;

        public void OnSingletonInit()
        {
           
        }

		public bool IsWalkPlaying { get; private set; } = false;

		private IActionController m_WalkAction;

		public int WalkInFrames = 20;

		public void PlayWalk()
		{
            if (IsWalkPlaying) return;
            if (m_WalkAction == null)
			{
                m_WalkAction = ActionKit.Repeat()
                .Callback(() => SFX_Walk2.Play())
                .DelayFrame(WalkInFrames)
                .Callback(() => SFX_Walk3.Play())
                .DelayFrame(WalkInFrames)
                .Callback(() => SFX_Walk4.Play())
                .DelayFrame(WalkInFrames)
                .Start(this);
            }
			

            IsWalkPlaying = true;
		}

		public void StopWalk()
		{
			if (!IsWalkPlaying) return;
			if (m_WalkAction != null)
			{
				m_WalkAction.Deinit();
				m_WalkAction = null;
			}

            IsWalkPlaying = false;
        }
	}
}
